package com.example.apidemo.net;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.CorsRegistry;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

@Configuration
public class WebConfig implements WebMvcConfigurer {
    @Autowired
    private LoginCheckInterceptor loginCheckInterceptor;

    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        /**
         * 定义拦截对象
         * addPathPatterns 拦截
         * excludePathPatterns 放行
         */

        registry.addInterceptor(loginCheckInterceptor)
                .addPathPatterns("/api/**")
                .excludePathPatterns("/sql/**")
                //.excludePathPatterns("/sql/inder")
                .excludePathPatterns("/txt/**")
//                .excludePathPatterns("/files/upload")
//                .excludePathPatterns("/files/upload/multiple")
//                .excludePathPatterns("/files/download/{fileName:.+}")
                .excludePathPatterns("/api/login")
                .excludePathPatterns("/api/aip")
                .excludePathPatterns("/api/text");
    }

//    @Override
//    public void addCorsMappings(CorsRegistry registry) {
//        registry.addMapping("/**")
//                .allowedOrigins("http://localhost:8080") // 替换为你的Flutter Web应用的实际源
//                .allowedMethods("GET", "POST");
//    }
}
